//
//  CYShowPayBackTableVC.m
//  CreditAddressBook
//
//  Created by LE on 16/1/4.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "CYShowPayBackTableVC.h"
#import "CYCreditTool.h"
#import "CYPayBack.h"
#import "MBProgressHUD+MJ.h"

@interface CYShowPayBackTableVC ()

@property (strong, nonatomic) NSArray *payBacks;//还款展示数据
@end

@implementation CYShowPayBackTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadPayBacks];
}

- (void)loadPayBacks {
    [MBProgressHUD showMessage:nil toView:self.view];
    [CYCreditTool payBacksWithParams:nil success:^(NSArray *payBacks) {
        [MBProgressHUD hideHUDForView:self.view];
        self.payBacks = payBacks;
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        CYLog(@"还款展示链接服务器失败：%@", error);
    }];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.payBacks.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"payBackCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    CYPayBack *payBack = self.payBacks[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:12];
    cell.textLabel.numberOfLines = 0;
    NSString *dateFormat = [CYCreditTool timewithLongLongValue:payBack.createTime.longLongValue formatter:nil];
    NSString *personName = @"*";
    if (payBack.lenderPerson && ![payBack.lenderPerson isEqualToString:@""]) {
        personName = [payBack.lenderPerson substringToIndex:1];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"    %@**于%@在“中国诚信联盟”的见证下，已将款项%@元支付给%@**，履行还款义务，目前系统已对%@**进行下线。", [payBack.lenderPerson substringToIndex:1], dateFormat, payBack.price, [payBack.name substringToIndex:1], [payBack.lenderPerson substringToIndex:1]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}
@end
